<template>
  <div class="log">
    <div class="login"></div>
    <el-form :model="form" :rules="rules" ref="form">
      <el-form-item>
        <h1 style="width: 100%; color: #fff; text-align: center">
          扬帆二手车后台管理系统
        </h1>
      </el-form-item>
      <el-form-item>
        <h2 style="width: 100%; color: #fff; text-align: center">欢迎登录</h2>
      </el-form-item>
      <el-form-item prop="username">
        <el-input
          id="user"
          v-model="form.username"
          suffix-icon="el-icon-s-custom"
          placeholder="请输入账号"
        ></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          @keyup.native.enter="submit"
          v-model="form.password"
          show-password
          type="password"
          placeholder="请输入密码"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          style="
            background: linear-gradient(#5f9aff, #50cfff);
            width: 100%;
            color: #fff;
          "
          @click="submit"
          >立即登录</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "请填写用户名", trigger: "blur" },
          {
            pattern: /^\w{3,15}$/,
            message: "3~15位字符，可以包含：数字、字母、下划线",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请填写密码", trigger: "blur" },
          {
            pattern: /^\w{6,15}$/,
            message: "6~15位字符，可以包含：数字、字母、下划线",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$store.dispatch("login", this.form);
        }
      });
    },
  },
};
</script>

<style lang="scss">
.log {
  width: 100vw;
  height: 100vh;
  position: relative;
  .login {
    background-image: url("../../../public/img/login.jpg");
    background-size: contain;
    width: 100%;
    height: 100%;
  }
  .el-form {
    width: 340px;
    position: absolute;
    height: 500px;
    top: 210px;
    left: 800px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
}

</style>